window.onload = function() {
    //获取cookie
    let cookieStr = document.cookie;
    let cookirArr = cookieStr.split(";");
    let bool = false;
    let username;
    for (let i = 0; i < cookirArr.length; i++) {
        //去除空格
        let str = cookirArr[i].trim();

        let key = "username=";
        if (str.startsWith(key)) {
            bool = true;
            username = str.substring(key.length, str.length);
            break;
        }
    }

    //判断bool标记值
    if (bool) {
        console.log(username);
    } else {
        location.href = "./01-首页.html"
    }
}